# -*- coding: utf-8 -*-
#(c)Jonathan & Gregoire (read __doc__ for more information)
#Copyright (C)%(author)s (%(date)s)
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

## @package view
# It is a collection of view object for implement MVC pattern design

from engine.view.Color import Color

__author__      = \
"""
Jonathan MERCIER <bioinfornatics at gmail.com >
Gregoire NAUDIN  <greg.naudin at gmail.com    >

"""
__version__     = "$Revision: 0.1 $"
__date__        = "$Date: 2009/23/09$"
__copyright__   = "Copyright (c) 2009 Jonathan MERCIER and Gregoire NAUDIN"
__license__     = "GPL v3 or under"
__name__        = "Player_view.py"
__description__ = \
"""
Player_view is a class between the player and the pattern Human/Computer
"""

## Documentation for Human_view class
# Player_view is a class between the physical player and the pattern Human
class Player_view(object):
    ## The constructor
    # @param self: The pointer object 
    def __init__(self):
        pass
    
    ## Public method set_player_type
    # @param self: The pointer object 
    def set_player_type(self):
        print u"Enter the player type"
        print u"\t- human"
        print u"\t- computer"
        type = raw_input()
        return player_type
        
    ## Public method set_player_name
    # @param self: The pointer object 
    # @param number: The player number
    # @param type: The type of player (human or computer)
    def set_player_name(self,type,number):
        color = Color()
        print type,u" player ",color.magenta(),number,color.end(),u" enter your name: ",
        player_name = raw_input()
        return player_name
     ## Public method set_player_name
    # @param self: The pointer object 
    # @param name: The player name       
    def name_already_use(self,name):
        color = Color()
        print u"Sorry the player name: ",color.magenta(),name,color.end()," is already used!"
        print u"Please choose an another name"
        
    ## Public method set_player_team
    # @param self: The pointer object 
    # @param number: The player number    
    # @param type: The type of player (human or computer)
    def set_player_team(self,type,number):
        color = Color()
        try:
            print type,u" player ",color.magenta(),number,color.end(),u" enter your team: ",
            player_team = input()
        except NameError:
            player_team = None
        except  SyntaxError:
            player_team = None
        print u"-"*40
        return player_team
    
    ## Public method set_player
    # @param self: The pointer object 
    # @param value: The player pointer object 
    def set_player(self,value):
        player = value
        
    def ask_which_card_need_be_selected(self,card_remaining):
        print u"Which card would you like selected?"
        print u"Choose an integer between 1 and ",card_remaining,": ",
        try:
            number = input()
        except NameError:
            number = None
        except  SyntaxError:
            number = None
        return number
    
    ## Public method rotate_card
    # @param self: The object pointer
    # @return: degree
    def rotate_card(self):
        print u"For turn card, choose rotate degree (in the sense of clockwise) between these values without symbol '°':"
        print u"\t0, 90°, 180°, 270° and -90°, -180°, -270°,1 (for horizontal flip),-1 (for vertical flip)"
        print u"Your choice: ",
        try :
            degree = input()
        except NameError:
            degree = None
        except  SyntaxError:
            degree = None
        return degree
    
    ## Public method which_action
    # @param self: The object pointer
    # @param name: The player name
    # @return:  choice
    def which_action(self,name):
        color = Color()
        try:
            print u"Player ",color.magenta(),name,color.end(),"what did you want to do?"
            print u"\t1/ Rotate a card"
            print u"\t2/ Drop a card"
            print u"\t3/ Skip your turn"
            print u"Your choice: ",
            choice = input()
        except NameError:
            choice = None
        except  SyntaxError:
            choice = None
        return choice
    
    ## Private method __beautiful_print
    # @param self: The object pointer
    # @param text: The text who need be colored
    # @return: color_text A colored text
    def __beautiful_print(self,text):
        color = Color()
        if text == u'F':
            color_text = color.green()+text+color.end()
        elif text == u'R' or text == u'S':
            color_text = color.blue()+text+color.end()
        elif text == u'P':
            color_text = color.yellow()+text+color.end()
        else:
            color_text = text
        return color_text
    
    ## Public method show_card
    # @param self: The object pointer
    # @param name: The player name
    # @param card: Pointer to a card object 
    def show_card(self,name,card):
        color = Color()
        print u'The player: ',color.magenta(),name,color.end(),u' take this card'
        print u''
        print u'_'*9
        print u'|',self.__beautiful_print(card.get_border_up_left()),self.__beautiful_print(card.get_border_up()),self.__beautiful_print(card.get_border_up_right()),u'|'
        print u'|',self.__beautiful_print(card.get_border_left()),self.__beautiful_print(card.get_middle()),self.__beautiful_print(card.get_border_right()),u'|'
        print u'|',self.__beautiful_print(card.get_border_down_left()),self.__beautiful_print(card.get_border_down()),self.__beautiful_print(card.get_border_down_right()),u'|'
        print u'_'*9
        print u''
        
    
    ## Public method choice_not_understand
    # @param self: The object pointer
    # @param choice: the choice enter by the player
    def choice_not_understand(self,choice):
        color = Color()
        print u'Sorry, your choice: ',color.magenta(),choice,color.end(),u' didn\'t have understood'
        print u'Please enter gain your choice, thanks'
        
    ## Public method show_hand
    # @param self: The object pointer
    # @param list_card: A list of card
    def show_hand(self,list_card):
        i   = 0
        
        for i in range(1,len(list_card)):
            print u'  ',i,u'        ',
        print u'\n',
        for i in  range(1,len(list_card)):
            print u'_'*9,'   ',
        print u'\n',
        list_card.pop(0)
        for card in list_card:
            print u'|',self.__beautiful_print(card.get_border_up_left()),self.__beautiful_print(card.get_border_up()),self.__beautiful_print(card.get_border_up_right()),u'|    ',
        print u'\n',
        for card in list_card:
            print u'|',self.__beautiful_print(card.get_border_left()),self.__beautiful_print(card.get_middle()),self.__beautiful_print(card.get_border_right()),u'|    ',
        print u'\n',
        for card in list_card:
            print u'|',self.__beautiful_print(card.get_border_down_left()),self.__beautiful_print(card.get_border_down()),self.__beautiful_print(card.get_border_down_right()),u'|    ',
        print u'\n',
        for i in  range(len(list_card)):
            print u'_'*9,'   ',
        print u'\n'

    ## Private method __beautiful_print
    # @param self The object pointer
    # @param text: The text who need be colored
    # @return: color_text A colored text
    def __beautiful_print(self,text):
        color = Color()
        if text == u'F':
            color_text = color.green()+text+color.end()
        elif text == u'R' or text == u'S':
            color_text = color.blue()+text+color.end()
        elif text == u'P':
            color_text = color.yellow()+text+color.end()
        else:
            color_text = text
        return color_text
    
    ## Public method current_score
    # @param self The object pointer
    # @param player: The pointer to player object
    def current_score(self,player):
        color = Color()
        print u"The player ",color.magenta(),player.get_name(),color.end(),u"curently has ",color.blue(),player.get_score(),color.end(),u" points\n\n"